<script setup>
import { useRouter } from "vue-router";
const router = useRouter();
import Breadcrumb from "@/components/Breadcrumb.vue";
import { getDailyRecom } from "@/api/admin";
import { ref, onMounted } from "vue";

// 面包屑数据
const breadcrumbData = [
  {
    name: "每日推荐",
    router: "/index",
  },
];
const dailyRecomData = ref([]);
const getDailyRecomData = async (page = 1) => {
  const res = await getDailyRecom({ page });
  dailyRecomData.value = res.data.data;
  console.log(dailyRecomData.value);
};
// 跳转到上传页面
const handleUpload = () => {
  router.push("/daily-recom-upload");
};

onMounted(() => {
  getDailyRecomData();
});
</script>

<template>
  <div class="daily-page">
    <Breadcrumb :pagData="breadcrumbData" />
    <div class="content">
      <div class="operation-bar">
        <el-button type="primary" @click="handleUpload">
          上传每日推荐
        </el-button>
      </div>

      <div class="list-content">
        <div class="item" v-for="item in dailyRecomData" :key="item._id">
          <div class="left">
            <img :src="item.imageUrl" alt="" />
          </div>
          <div class="info">
            <div class="title">
              <h3>{{ item.title }}</h3>
            </div>
            <div class="details">
              <p><span class="label">地址：</span>{{ item.address }}</p>
              <p>
                <span class="label">颜色值：</span
                ><span
                  class="color-block"
                  :style="{ background: item.color }"
                ></span
                >{{ item.color }}
              </p>
              <p><span class="label">添加时间：</span>{{ item.time }}</p>
            </div>
          </div>
          <div class="operation">
            <el-button type="danger" size="small">删除</el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.daily-page {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;

  .content {
    margin-top: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    margin-bottom: 20px;

    .operation-bar {
      padding: 20px;
      border-bottom: 1px solid #f0f0f0;
      background: #fff;
      z-index: 1;

      .el-button {
        padding: 0 25px;
        height: 40px;
        font-weight: 500;
        transition: all 0.3s;

        &:hover {
          transform: translateY(-2px);
          box-shadow: 0 4px 12px rgba(64, 158, 255, 0.2);
        }
      }
    }

    .list-content {
      flex: 1;
      padding: 20px;
      overflow-y: auto;

      &::-webkit-scrollbar {
        width: 6px;
      }

      &::-webkit-scrollbar-thumb {
        background: #ddd;
        border-radius: 3px;
      }

      .item {
        padding: 20px;
        margin-bottom: 20px;
        border-radius: 12px;
        background: #f8f9fa;
        display: flex;
        align-items: center;
        transition: all 0.3s;

        &:hover {
          transform: translateY(-2px);
          box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
        }

        .left {
          width: 200px;
          height: 150px;
          margin-right: 30px;
          border-radius: 8px;
          overflow: hidden;
          box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: all 0.4s ease;

            &:hover {
              transform: scale(1.08);
            }
          }
        }

        .info {
          flex: 1;
          padding-right: 20px;

          .title h3 {
            font-size: 18px;
            color: #2c3e50;
            margin-bottom: 20px;
            font-weight: 600;
          }

          .details p {
            margin-bottom: 12px;
            color: #666;
            font-size: 14px;
            display: flex;
            align-items: center;

            .label {
              color: #999;
              width: 80px;
              font-weight: 500;
            }

            .color-block {
              width: 20px;
              height: 20px;
              border-radius: 4px;
              margin: 0 10px;
              border: 2px solid #fff;
              box-shadow: 0 0 4px rgba(0, 0, 0, 0.1);
            }
          }
        }

        .operation {
          .el-button {
            padding: 8px 20px;
            font-weight: 500;

            &:hover {
              transform: translateY(-1px);
              box-shadow: 0 4px 12px rgba(245, 108, 108, 0.2);
            }
          }
        }
      }
    }
  }
}
</style>
